#include <bits/stdc++.h>
using namespace std;
const int _ = 2e5 + 10;
int cnt, x[_], y[_];
inline void ins(int a, int b) {
    cnt++;
    x[cnt] = a;
    y[cnt] = b;
}
inline void solve00(int n, int m) {
    for (int i = 1; i <= n; i++) {
        ins(i, 1);
    }
    for (int i = 1; i <= n; i++) {
        ins(i, m);
    }
    for (int i = (n >> 1) + 2; i <= m - (n >> 1) - 1; i++) {
        ins((n >> 1), i);
    }
}
inline void solve01(int n, int m) {
    for (int i = 1; i <= n; i++) {
        ins(i, 1);
    }
    for (int i = 1; i <= n; i++) {
        ins(i, m);
    }
    for (int i = (n >> 1) + 2; i <= m - (n >> 1) - 1; i += 2) {
        ins((n >> 1), i);
        ins((n >> 1) + 1, i);
    }
}
inline void solve10(int n, int m) {
    for (int i = 1; i <= n; i++) {
        ins(i, 1);
    }
    for (int i = 1; i <= n; i++) {
        ins(i, m);
    }
    for (int i = ((n + 1) >> 1) + 1; i <= m - ((n + 1) >> 1); i++) {
        ins(((n + 1) >> 1), i);
    }
}
inline void solve11(int n, int m) {
    for (int i = 1; i <= n; i++) {
        ins(i, 1);
    }
    for (int i = 1; i <= n; i++) {
        ins(i, m);
    }
    for (int i = ((n + 1) >> 1) + 1; i <= m - ((n + 1) >> 1); i++) {
        ins(((n + 1) >> 1), i);
    }
}
inline void solve(int n, int m) {
    if (n == m) {
        for (int i = 1; i <= n; i++) {
            ins(i, 1);
        }
        for (int i = 2; i < n; i++) {
            ins(i, m);
        }
    } else if (n + 1 == m) {
        for (int i = 1; i <= n; i++) {
            ins(i, 1);
        }
        for (int i = 1; i <= n; i++) {
            ins(i, m);
        }
    } else if (n & 1) {
        if (m & 1) {
            solve11(n, m);
        } else {
            solve10(n, m);
        }
    } else {
        if (m & 1) {
            solve01(n, m);
        } else {
            solve00(n, m);
        }
    }
}
int main() {
    freopen("bishop.in", "r", stdin);
    freopen("bishop.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    if (n > m) {
        solve(m, n);
        cout << cnt << '\n';
        for (int i = 1; i <= cnt; i++) {
            cout << y[i] << ' ' << x[i];
            if (i != cnt) cout << '\n';
        }
    } else {
        solve(n, m);
        cout << cnt << '\n';
        for (int i = 1; i <= cnt; i++) {
            cout << x[i] << ' ' << y[i];
            if (i != cnt) cout << '\n';
        }
    }
    cout << endl;
    return 0;
}